<!DOCTYPE html>
<html  lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>购买记录</title>
    <th:block th:include="~{common/common::commonHead}"/>
</head>
<style>
    .panel-heading>.fl-right{
        cursor: pointer;
        color: #ccc;
        padding: 0 6px 0 18px;
    }
    .panel-heading>.fl-right:hover{
        color: #bbb;
    }
    .panel-heading>.fl-right>i{
        margin-right: 2px;
        font-size: 12px;
        color: #ccc;
    }
    .panel-heading>.fl-right:hover i{
        margin-right: 3px;
        font-size: 12px;
        color: #bbb;
    }
</style>
<!-- /Head -->
<!-- Body -->
<body>
<!-- Page Body -->
<div class="page-body">
    <div class="panel panel-primary">
        <div class="panel-heading bg-blue">
            购买列表
            <a class="fl-right" id="go" onClick="javascript:history.back(-1);"><i class="glyphicon glyphicon-menu-left"></i>返回</a>
        </div>
        <div class="widget-body grid-table">
            <div class="toolbar">
                <div class="fl-left">
                    <button class="btn btn-blue shiny" id="notReceived">未收货</button>
                    <button class="btn shiny" id="received" value="10">已收货</button>
                </div>
            </div>
            <div id="confirmReceipt"></div>
        </div><!-- end of panel -->
    </div>
    <!-- /Page Container -->
    <!-- Main Container -->
</div>
</body>
<!--  /Body -->
</html>
<script>
    (function($){
        $.getUrlParam
            = function(name)
        {
            var reg
                = new RegExp("(^|&)"+
                name +"=([^&]*)(&|$)");
            var r
                = window.location.search.substr(1).match(reg);
            if (r!=null) return unescape(r[2]); return null;
        }
    })(jQuery);
    $(function () {
        var prisonerId=$.getUrlParam('prisonerId');
        $("#confirmReceipt").gridTable({
            url: "orderPrisoner/pageByPrisonerId",
            columns: [
                {title: "订单号", field: "id",},
                {title: "犯人姓名", field: "prisonerName"},
                {title: "监区", field: "area"},
                {title: "分监区", field: "subArea"},
                {title: "状态", field: "status",format:toStatus},
                {title: "已发数量", field: "totalInvoice",dataType:"number"},
                {title: "商品总数量", field: "totalCount",dataType:"number"},
                {title: "订单总额", field: "totalMoney",dataType:"decimal"},
                {title: "创建时间", field: "createTime"},
                {title: "确认收货", field: "id",format:function(id,dx,row){
                    return " <a  class='con-receipt' id='receipt'  onclick='confirm( \"" + id + "\");'>[确认收货]</a>"

                }},
                {title: "操作", field: "id",format:function(id,dx,row){
                    return " <a  class='con-receipt' onclick='detail("+id+")'>[查看详情]</a>"
                }}
            ],
            pageSize: 10,
            params:{prisonerId:prisonerId},
            idField: "id",
            onDoubleClickRow: function(){},
            showControl:false,
            showCheckbox:false
        });
        //已收货
        $("#received").on("click",function(){
            $(this).siblings().removeClass("btn-blue");
            $(this).addClass("btn btn-blue");
            $("#confirmReceipt").empty().gridTable({
                url: "orderPrisoner/pageByPrisonerIdFinish",
                columns: [
                    {title: "订单号", field: "id"},
                    {title: "犯人姓名", field: "prisonerName"},
                    {title: "监区", field: "area"},
                    {title: "分监区", field: "subArea"},
                    {title: "状态", field: "status",format:toStatus},
                    {title: "已发数量", field: "totalInvoice",dataType:"number"},
                    {title: "商品总数量", field: "totalCount",dataType:"number"},
                    {title: "订单总额", field: "totalMoney",dataType:"decimal"},
                    {title: "创建时间", field: "createTime"},
                    {title: "操作", field: "id",format:function(id,dx,row){
                        return " <a  class='con-receipt' onclick='detail("+id+")'>[查看详情]</a>"
                    }}
                ],
                pageSize: 10,
                params:{prisonerId:prisonerId},
                idField: "id",
                onDoubleClickRow: function(){},
                showControl:false,
                showCheckbox:false
            });
        });
        //未收货
        $("#notReceived").on("click",function(){
            $(this).siblings().removeClass("btn-blue");
            $(this).addClass("btn btn-blue");
            $("#confirmReceipt").empty().gridTable({
                url: "orderPrisoner/pageByPrisonerId",
                columns: [
                    {title: "订单号", field: "id"},
                    {title: "犯人姓名", field: "prisonerName"},
                    {title: "监区", field: "area"},
                    {title: "分监区", field: "subArea"},
                    {title: "状态", field: "status",format:toStatus},
                    {title: "已发数量", field: "totalInvoice",dataType:"number"},
                    {title: "商品总数量", field: "totalCount",dataType:"number"},
                    {title: "订单总额", field: "totalMoney",dataType:"decimal"},
                    {title: "创建时间", field: "createTime"},
                    {title: "确认收货", field: "id",format:function(id,dx,row){
                        return " <a  class='con-receipt' id='receipt' onclick='confirm(\"+id+\");'>[确认收货]</a>"
                    }},
                    {title: "操作", field: "id",format:function(id,dx,row){
                        return " <a  class='con-receipt' onclick='detail(\"+id+\")'>[查看详情]</a>"
                    }}
                ],
                pageSize: 10,
                params:{prisonerId:prisonerId},
                idField: "id",
                onDoubleClickRow: function(){},
                showControl:false,
                showCheckbox:false
            });
        });
    });
    //判断状态
    function toStatus(status){
        switch (status) {
            case '2':
                return "<span class='label label-orange'>已审核</span>";
            case '1':
                return "<span class='label label-default'>待审核</span>";
            case '4':
                return "<span class='label label-yellow'>配送中</span>";
            case '5':
                return "<span class='label label-warning'>部分收货</span>";
            case '9':
                return "<span class='label label-warning'>请确认收货</span>";
            case '10':
                return "<span class='label label-success'>已收货</span>";
            case '99':
                return "<span class='label label-danger'>审核不通过</span>";
            default:
                return status;
        }
    }


    //确认收货
    function confirm(id) {
        alert(id);
        var gridTable =$$selection.get("gridTable","confirmReceipt");

       // var id="58226089092186112";

        $.confirm({
            title: "收货",
            icon: "fa fa-question-circle-o",
            content: "<p>确认收到当前订单的商品了吗？</p>",
            theme: "modern",
            type: "orange",
            buttons:{
                ok:{
                    text: "确认",
                    btnClass: "btn-primary",
                    action:function(){
                        var scb = function () {
                            $.success("操作成功：收到了当前订单商品");
                            gridTable.reloadData();
                        };
                        var ecb = function (error) {
                            $.error(error.msg);
                        };
                        $.doAjax("orderPrisoner/settlement",{"idStr":id},scb,ecb);
                    }
                },
                cancel: {
                    text: "取消",
                    btnClass: "btn-success",
                    action: function () {
                        gridTable.reloadData();
                    }
                }
            }
        });
    }
    //查看详情
    function detail(id) {
        var gridTable =$$selection.get("gridTable","confirmReceipt");
        var dialog = $.openIframeDialog({
            title:"点单详情",
            param: {
                id:id
            },
            url: "order/prisonerOrderInfo.html",
            buttons: {
                ok: {show: false},
                cancel: {show: false}
            }
        });
    }
</script>
